using System.Text;

namespace OracleInternal.SqlAndPlsqlParser.LocalParsing
{
	public abstract class OracleLpStatementElement
	{
		protected OracleLpStatementElement m_vParent;

		private string m_vDepthIndent;

		private OracleLpStatementElement m_vTopElement;

		internal int Depth
		{
			get
			{
				if (m_vParent != null)
				{
					return m_vParent.Depth + 1;
				}
				return 0;
			}
		}

		internal OracleLpStatementElement Parent
		{
			get
			{
				return m_vParent;
			}
			set
			{
				m_vParent = value;
			}
		}

		internal string DepthIndent
		{
			get
			{
				if (m_vDepthIndent == null)
				{
					m_vDepthIndent = new string(' ', 4 * Depth);
				}
				return m_vDepthIndent;
			}
		}

		internal OracleLpStatementElement TopElement
		{
			get
			{
				if (m_vTopElement == null)
				{
					OracleLpStatementElement oracleLpStatementElement = this;
					while (oracleLpStatementElement.m_vParent != null)
					{
						oracleLpStatementElement = oracleLpStatementElement.m_vParent;
					}
					m_vTopElement = oracleLpStatementElement;
				}
				return m_vTopElement;
			}
		}

		internal abstract OracleLpStatementElementType ElementType
		{
			get;
		}

		internal OracleLpStatementElement(OracleLpStatementElement parent)
		{
			m_vParent = parent;
		}

		internal OracleLpQueryBlock GetParentQueryBlock()
		{
			for (OracleLpStatementElement oracleLpStatementElement = m_vParent; oracleLpStatementElement != null; oracleLpStatementElement = oracleLpStatementElement.Parent)
			{
				if (oracleLpStatementElement.ElementType == OracleLpStatementElementType.QueryBlock)
				{
					return oracleLpStatementElement as OracleLpQueryBlock;
				}
			}
			return null;
		}

		internal abstract void ToString(StringBuilder sb);
	}
}
